﻿@* Generator: Template *@
@functions { public dynamic Model { get; set; } }@{var dotModule = Model.Module == null ? "" : ("." + Model.Module); var modulePrefix = (Model.Module == null ? "" : (Model.Module + "/"));
}
namespace @(Model.RootNamespace)@(dotModule).Endpoints
{
    using Serenity;
    using Serenity.Data;
    using Serenity.Services;
    using System.Data;
    using System.Web.Mvc;
    using MyRepository = Repositories.@(Model.ClassName)Repository;
    using MyRow = Entities.@(Model.RowClassName);

    [RoutePrefix("Services/@(modulePrefix)@(Model.ClassName)"), Route("{action}")]
    [ConnectionKey("@Model.ConnectionKey"), ServiceAuthorize("@(Model.Permission)")]
    public class @(Model.ClassName)Controller : ServiceEndpoint
    {
        [HttpPost]
        public SaveResponse Create(IUnitOfWork uow, SaveRequest<MyRow> request)
        {
            return new MyRepository().Create(uow, request);
        }

        [HttpPost]
        public SaveResponse Update(IUnitOfWork uow, SaveRequest<MyRow> request)
        {
            return new MyRepository().Update(uow, request);
        }
 
        [HttpPost]
        public DeleteResponse Delete(IUnitOfWork uow, DeleteRequest request)
        {
            return new MyRepository().Delete(uow, request);
        }

        public RetrieveResponse<MyRow> Retrieve(IDbConnection connection, RetrieveRequest request)
        {
            return new MyRepository().Retrieve(connection, request);
        }

        public ListResponse<MyRow> List(IDbConnection connection, ListRequest request)
        {
            return new MyRepository().List(connection, request);
        }
    }
}
